#ifndef BUTTON_H
#define BUTTON_H

#include <Arduino.h>

class Button {
    typedef void (*cb_func)();
public:
    Button(uint8_t pin, cb_func short_press_func, cb_func long_press_func);
    enum class KeyState {
        IDLE,
        SHORT_PRESS,
        LONG_PRESS,
    };

    void begin(uint32_t interval);

    bool is_pressed();

    KeyState get_key_state();

    void run();

private:
    uint8_t pin;

    cb_func short_press_func;
    cb_func long_press_func;

    KeyState cur_key_state;
    uint32_t press_time;

    uint32_t pre_millis;
    uint32_t interval;

    static const uint32_t short_press_time = 50;
    static const uint32_t long_press_time = 500;
};

#endif